package com.briup.mt.service.impl;

import com.briup.mt.bean.Dataset;
import com.briup.mt.bean.DatasetExample;
import com.briup.mt.dao.DatasetMapper;
import com.briup.mt.service.IFileDatasetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author pete
 * @version 1.0
 * @date 2020/12/16 11:38
 */
@Service
public class FileDatasetServiceImpl implements IFileDatasetService {
    @Autowired
    private DatasetMapper datasetMapper;

    @Override
    public List<Dataset> query(String name){
        DatasetExample example = new DatasetExample();
        if(!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%"+name+"%");
        }
        return datasetMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(Dataset dataset){
        if (dataset.getId() == null) {
            datasetMapper.insert(dataset);
        }else{
            datasetMapper.updateByPrimaryKey(dataset);
        }
    }

    @Override
    public void deleteById(long id) {

        datasetMapper.deleteByPrimaryKey(id);
    }
}

